import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';


import { Subscription } from 'rxjs';
import { AddFriendProvider } from './add-friend.provider';

@IonicPage()
@Component({
  selector: 'page-add-friend',
  templateUrl: 'add-friend.html',
  providers:[ AddFriendProvider ]
})
export class AddFriendPage {

  lists: any = [];

  user: any;

  searchName: string = '';

  constructor(public navCtrl: NavController, public navParams: NavParams,private service:AddFriendProvider) {
    
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad AddFriendPage');
  }

  search(val){

    if(val == ''){
      return;
    }

    this.getHttp(val);
  }

  listenEvent:Subscription;
  getHttp(search){

    this.listenEvent = this.service.searchFriend({searchName:search}).subscribe((res:any)=>{
      this.lists = res.data;
    });
  }

 
  ionViewWillLeave() {
    if (this.listenEvent) {
      this.listenEvent.unsubscribe();
    }
  }
}
